package com.xcity.game.combat.calc.impl;

import java.util.List;

import com.xcity.db.entity.Player;
import com.xcity.game.combat.CombatUtils;
import com.xcity.game.combat.attr.CombatAttributeType;
import com.xcity.game.combat.calc.CombatAttributeCalculator;
import com.xcity.game.employee.EmployeeService;
import com.xcity.game.employee.template.EmployeeQualityUpTemplate;
import com.xcity.game.player.PlayerTrainService;
import com.xcity.game.player.template.DestinyTemplate;
import com.xcity.game.skill.v2.DefaultSkillV2;

import naga.x.App;

public class PlayerCombatAttributeCalculator extends CombatAttributeCalculator<Player> {

	public PlayerCombatAttributeCalculator(Player unit) {
		super(unit);
	}

	@Override
	protected float calc(CombatAttributeType type) {
		// 总数值=基础值+技能加成
		// 1. 基础值=升级+升品+升星/升天命
			// 升级
		float val = CombatUtils.getDefaultPlayerTemplate().calc(type, unit.getLevel());
			// 升品
		if (unit.getQualityLvl() > 0) {
			List<EmployeeQualityUpTemplate> templates = App.getApp().getServiceManager().get(EmployeeService.class).configure().getQualityLevelUpConfigure().getTemplates(PlayerTrainService.QUALITY_LEVEL_UP_TEMPLATE_ID);
			for (int i = 0, size = templates.size(); i < size; i++) {
				EmployeeQualityUpTemplate template = templates.get(i);
				if (template.getLevel() > unit.getQualityLvl()) {
					break;
				}
				val += template.getAttributeValue(type);
			}
		}
			// 升星/升天命
		if (unit.getDestinyLvl() > 0) {
			List<DestinyTemplate> templates = App.getApp().getServiceManager().get(PlayerTrainService.class).getDestinyTemplates();
			for (int i = 0, size = templates.size(); i < size; i++) {
				DestinyTemplate template = templates.get(i);
				if (template.getLevel() > unit.getDestinyLvl()) {
					break;
				}
				val += template.getAttributeValue(type);
			}
		}
		// 2. 技能加成
		float baseVal = val;
		List<DefaultSkillV2> skills = unit.getSkillManager().getPassives();
		for (int i = 0, size = skills.size(); i < size; i++) {
			val += skills.get(i).enhance(type, baseVal);
		}
		return val;
	}
	
}
